package it.carlom.stickyheader.example.fragment;


import it.carlom.stickyheader.ResourceTable;
import it.carlom.stickyheader.example.Utils;
import it.carlom.stickyheader.example.adapter.TextAdapter;
import it.carlom.stikkyheader.core.StikkyHeaderBuilder;
import it.carlom.stikkyheader.core.animator.AnimatorBuilder;
import it.carlom.stikkyheader.core.animator.HeaderStikkyAnimator;
import it.carlom.stikkyheader.core.utils.PxUtil;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ListContainer;

public class ParallaxStikkyFragment extends BaseFraction {

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        return scatter.parse(ResourceTable.Layout_fragment_parallax, container, false);
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        ListContainer listView = (ListContainer) getComponent().findComponentById(ResourceTable.Id_listview);
        Component header = getComponent().findComponentById(ResourceTable.Id_header);
        listView.setItemProvider(new TextAdapter(getFractionAbility(), Utils.getData()));

        StikkyHeaderBuilder.stickTo(listView).setHeader(header)
                .minHeightHeader((int) PxUtil.vp2px(120))
                .animator(new ParallaxStikkyAnimator())
                .build();
    }


    private static class ParallaxStikkyAnimator extends HeaderStikkyAnimator {
        @Override
        public AnimatorBuilder getAnimatorBuilder() {
            Component mHeader_image = getHeader().findComponentById(ResourceTable.Id_header_image);
            return AnimatorBuilder.create().applyVerticalParallax(mHeader_image);
        }
    }
}
